/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package czStvDpds.benchmark;

import czStvDpds.App;
import java.awt.HeadlessException;
import java.awt.TextArea;
import javax.swing.JFrame;
import org.lwjgl.opengl.*;

/**
 *
 * @author divad
 */
public class BenchmarkWindow extends JFrame {

    private String infos = "";

    public BenchmarkWindow() throws HeadlessException {
        App.addLibs();

        try {
            Display.setDisplayMode(new DisplayMode(640, 480));
            Display.setTitle("LWJGL benchmark - getting GL informations");
            Display.create();

            this.getGLInfos();
            infos += "\n";
            infos += "max texture size = " + GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE) + "\n";
            if (GLContext.getCapabilities().OpenGL12) {
                infos += "max 3D texture size = " + GL11.glGetInteger(GL12.GL_MAX_3D_TEXTURE_SIZE) + "\n";
            } else {
                infos += "max 3D texture size = ? to low GL\n";
            }
            if (GLContext.getCapabilities().OpenGL13) {
                infos += "max cube texture size = " + GL11.glGetInteger(GL13.GL_MAX_CUBE_MAP_TEXTURE_SIZE) + "\n";
            } else {
                infos += "max cube texture size = ? to low GL\n";
            }
            if (GLContext.getCapabilities().OpenGL20) {
                infos += "max texture image units = " + GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS) + "\n";
                infos += "max vertex texture image units = " + GL11.glGetInteger(GL20.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS) + "\n";
            } else if (GLContext.getCapabilities().OpenGL13) {
                infos += "max texture image units = " + GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS) + "\n";
                infos += "max vertex texture image units = ? to low GL\n";
            } else {
                infos += "max texture image units = ? to low GL\n";
                infos += "max vertex texture image units = ? to low GL\n";
            }

            Display.destroy();
        } catch (Exception e) {
            infos += e.getMessage();
        }
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.add(new TextArea(infos, 20, 35, TextArea.SCROLLBARS_BOTH));
        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    private void getGLInfos() {
        infos += "OpenGL version - " + this.getGLVersion() + "\n";
        infos += "ARB color buffer float - " + GLContext.getCapabilities().GL_ARB_color_buffer_float + "\n";
        infos += "ARB depth buffer float - " + GLContext.getCapabilities().GL_ARB_depth_buffer_float + "\n";
        infos += "ARB draw buffers - " + GLContext.getCapabilities().GL_ARB_draw_buffers + "\n";
        infos += "ARB fragment program - " + GLContext.getCapabilities().GL_ARB_fragment_program + "\n";
        infos += "ARB fragment shader - " + GLContext.getCapabilities().GL_ARB_fragment_shader + "\n";
        infos += "ARB framebuffer object - " + GLContext.getCapabilities().GL_ARB_framebuffer_object + "\n";
        infos += "ARB multisample - " + GLContext.getCapabilities().GL_ARB_multisample + "\n";
        infos += "ARB multitexture - " + GLContext.getCapabilities().GL_ARB_multitexture + "\n";
        infos += "ARB pixelbuffer object - " + GLContext.getCapabilities().GL_ARB_pixel_buffer_object + "\n";
        infos += "ARB shader objects - " + GLContext.getCapabilities().GL_ARB_shader_objects + "\n";
        infos += "ARB tesselation shader - " + GLContext.getCapabilities().GL_ARB_tessellation_shader + "\n";
        infos += "ARB texture border clamp - " + GLContext.getCapabilities().GL_ARB_texture_border_clamp + "\n";
        infos += "ARB texture cube map - " + GLContext.getCapabilities().GL_ARB_texture_cube_map + "\n";
        infos += "ARB texture float - " + GLContext.getCapabilities().GL_ARB_texture_float + "\n";
        infos += "ARB texture mirrored repeat - " + GLContext.getCapabilities().GL_ARB_texture_mirrored_repeat + "\n";
        infos += "ARB texture non power of two - " + GLContext.getCapabilities().GL_ARB_texture_non_power_of_two + "\n";
        infos += "ARB texture env combine - " + GLContext.getCapabilities().GL_ARB_texture_env_combine + "\n";
        infos += "ARB texture env dot 3 - " + GLContext.getCapabilities().GL_ARB_texture_env_dot3 + "\n";
        infos += "ARB texture env add - " + GLContext.getCapabilities().GL_ARB_texture_env_add + "\n";
        infos += "ARB texture env crossbar - " + GLContext.getCapabilities().GL_ARB_texture_env_crossbar + "\n";
        infos += "ARB texture query lod - " + GLContext.getCapabilities().GL_ARB_texture_query_lod + "\n";
        infos += "ARB vertex program - " + GLContext.getCapabilities().GL_ARB_vertex_program + "\n";
        infos += "ARB vertex shader - " + GLContext.getCapabilities().GL_ARB_vertex_shader + "\n";
        infos += "ARB vertex buffer object - " + GLContext.getCapabilities().GL_ARB_vertex_buffer_object + "\n";
        infos += "\n";
        infos += "EXT framebuffer object - " + GLContext.getCapabilities().GL_EXT_framebuffer_object + "\n";
        infos += "EXT texture 3D - " + GLContext.getCapabilities().GL_EXT_texture_3d + "\n";
        infos += "EXT texture mirror clamp - " + GLContext.getCapabilities().GL_EXT_texture_mirror_clamp + "\n";
        infos += "EXT vertex shader - " + GLContext.getCapabilities().GL_EXT_vertex_shader + "\n";
        infos += "EXT seperate shader objects - " + GLContext.getCapabilities().GL_EXT_separate_shader_objects + "\n";
        infos += "EXT multy draw arrays - " + GLContext.getCapabilities().GL_EXT_multi_draw_arrays + "\n";
        infos += "EXT texture lod bias - " + GLContext.getCapabilities().GL_EXT_texture_lod_bias + "\n";
        infos += "EXT texture env combine - " + GLContext.getCapabilities().GL_EXT_texture_env_combine + "\n";
        infos += "EXT texture env dot 3 - " + GLContext.getCapabilities().GL_EXT_texture_env_dot3 + "\n";
        infos += "\n";
        infos += "SGIS texture lod - " + GLContext.getCapabilities().GL_SGIS_texture_lod + "\n";
        
    }

    private String getGLVersion() {
        if (GLContext.getCapabilities().OpenGL42) {
            return "4.2";
        } else if (GLContext.getCapabilities().OpenGL41) {
            return "4.1";
        } else if (GLContext.getCapabilities().OpenGL40) {
            return "4.0";
        } else if (GLContext.getCapabilities().OpenGL33) {
            return "3.3";
        } else if (GLContext.getCapabilities().OpenGL32) {
            return "3.2";
        } else if (GLContext.getCapabilities().OpenGL31) {
            return "3.1";
        } else if (GLContext.getCapabilities().OpenGL30) {
            return "3.0";
        } else if (GLContext.getCapabilities().OpenGL21) {
            return "2.1";
        } else if (GLContext.getCapabilities().OpenGL20) {
            return "2.0";
        } else if (GLContext.getCapabilities().OpenGL15) {
            return "1.5";
        } else if (GLContext.getCapabilities().OpenGL14) {
            return "1.4";
        } else if (GLContext.getCapabilities().OpenGL13) {
            return "1.3";
        } else if (GLContext.getCapabilities().OpenGL12) {
            return "1.2";
        } else if (GLContext.getCapabilities().OpenGL11) {
            return "1.1";
        } else {
            return "NONE";
        }
    }

    public static void main(String[] args) {
        System.setProperty("org.lwjgl.opengl.Display.allowSoftwareOpenGL", "true");
        new BenchmarkWindow();
    }
}
